/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
#include "MaCI_AlarmEventsConfigDialog.h"
#include "AlarmClient.hpp"


//*****************************************************************************
//*****************************************************************************

MaCI_AlarmEventsConfigDialog::MaCI_AlarmEventsConfigDialog( wxWindow* parent )
  :  EventsConfigDialog( parent )
{
}
//*****************************************************************************

MaCI_AlarmEventsConfigDialog::~MaCI_AlarmEventsConfigDialog(void)
{
  
}
//*****************************************************************************

void MaCI_AlarmEventsConfigDialog::OnCloseButtonClick( wxCloseEvent& event )
{
  EndModal(wxID_CLOSE);
}
//*****************************************************************************

void MaCI_AlarmEventsConfigDialog::OnOKButtonClick( wxCommandEvent& event )
{
  GetDialogState(iConfig);
  EndModal(wxID_OK);
}
//*****************************************************************************

void MaCI_AlarmEventsConfigDialog::OnCancelButtonClick( wxCommandEvent& event )
{
  EndModal(wxID_CANCEL);
}
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************

void MaCI_AlarmEventsConfigDialog::SetDialogState(const SEventsDisplayConfiguration &aConf)
{
  using namespace MaCI::Alarm;
  // Read boolean if limitEnabled
  this->limitDisplayedCheckBox->SetValue(aConf.isLimitEventsEnabled);

  // Read value
  long unsigned int uvalue;
  this->limitDisplayedEventTextCtrl->SetValue(wxString::Format("%u",aConf.eventLimit));

  // read enabled events.
  displayQuestionCheckBox->SetValue(aConf.enabledEvents & (1<<KEventTypeQuestion));
  displayErrorCheckBox->SetValue(aConf.enabledEvents & (1<<KEventTypeError));
  displayWarningCheckBox->SetValue(aConf.enabledEvents & (1<<KEventTypeWarning));
  displayNotificationCheckBox->SetValue(aConf.enabledEvents & (1<<KEventTypeNotification));
  displayInformationCheckBox->SetValue(aConf.enabledEvents & (1<<KEventTypeInfo));
  displayDebugCheckBox->SetValue(aConf.enabledEvents & (1<<KEventTypeDebug));

  // Read enabled actions
  this->enableQuestionsCheckBox->SetValue(aConf.isQuestionPopupEnabled);
  this->enableAckCheckBox->SetValue(aConf.isAckPopupEnabled);


}
//*****************************************************************************

void MaCI_AlarmEventsConfigDialog::GetDialogState(SEventsDisplayConfiguration &aConf)
{
  using namespace MaCI::Alarm;
  // Read boolean if limitEnabled
  aConf.isLimitEventsEnabled = this->limitDisplayedCheckBox->IsChecked();

  // Read value
  long unsigned int uvalue;
  if (this->limitDisplayedEventTextCtrl->GetValue().ToULong(&uvalue)) {
    aConf.eventLimit = uvalue;
  }

  // read enabled events.
  aConf.enabledEvents = 0;
  if (displayQuestionCheckBox->IsChecked()) aConf.enabledEvents |= (1<<KEventTypeQuestion);
  if (displayErrorCheckBox->IsChecked()) aConf.enabledEvents |= (1<<KEventTypeError);
  if (displayWarningCheckBox->IsChecked()) aConf.enabledEvents |= (1<<KEventTypeWarning);
  if (displayNotificationCheckBox->IsChecked())aConf.enabledEvents |= (1<<KEventTypeNotification);
  if (displayInformationCheckBox->IsChecked()) aConf.enabledEvents |= (1<<KEventTypeInfo);
  if (displayDebugCheckBox->IsChecked()) aConf.enabledEvents |= (1<<KEventTypeDebug);

  // Read action selectors
  aConf.isQuestionPopupEnabled = enableQuestionsCheckBox->IsChecked();
  aConf.isAckPopupEnabled = enableAckCheckBox->IsChecked();

}
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
